#pragma once

#include "Error.h"

namespace TestFramework
{
    template <class T>
    class TestStack
    {
    public:
        typedef T ValueType;

        TestStack()
            : Top(0)
        {
        }

        ~TestStack()
        {
            StackElement* backElement;
            while (Top != 0)
            {
                backElement = Top->back;
                delete Top;
                Top = backElement;
            }
        }

        void Push(const ValueType& value)
        {
            StackElement* element = new StackElement();
            element->data = value;
            element->back = (Top == 0) ? 0 : Top;
            Top = element;
        }

        ValueType Pop()
        {
            if (Top != 0)
            {
                ValueType tempData = Top->data;
                StackElement* tempBack = Top->back;
                delete Top;
                Top = tempBack;
                return tempData;
            }
            else
            {
                throw std::exception("Stack is empty!", Errors::STACK_IS_EMPTY);
            }
        }

    private:
        struct StackElement
        {
            ValueType data;
            StackElement* back;
        };

        StackElement* Top;
    };
}
